load("@io_bazel_rules_go//go:def.bzl", "go_test")
load("@bazel_skylib//lib:selects.bzl", "selects")
load("@prysm//tools/go:def.bzl", "go_library")

#  Build with --define=blst_enabled=false to exclude blst library.
config_setting(
    name = "blst_enabled_linux_amd64",
    constraint_values = [
        "@platforms//os:linux",
        "@platforms//cpu:x86_64",
    ],
    values = {
        "define": "blst_enabled=true",
    },
)

config_setting(
    name = "blst_enabled_darwin_amd64",
    constraint_values = [
        "@platforms//os:osx",
        "@platforms//cpu:x86_64",
    ],
    values = {
        "define": "blst_enabled=true",
    },
)

config_setting(
    name = "blst_enabled_windows_amd64",
    constraint_values = [
        "@platforms//os:windows",
        "@platforms//cpu:x86_64",
    ],
    values = {
        "define": "blst_enabled=true",
    },
)

config_setting(
    name = "blst_enabled_linux_arm64",
    constraint_values = [
        "@platforms//os:linux",
        "@platforms//cpu:aarch64",
    ],
    values = {
        "define": "blst_enabled=true",
    },
)

config_setting(
    name = "blst_enabled_android_amd64",
    constraint_values = [
        "@platforms//os:android",
        "@platforms//cpu:x86_64",
    ],
    values = {
        "define": "blst_enabled=true",
    },
)

config_setting(
    name = "blst_enabled_android_arm64",
    constraint_values = [
        "@platforms//os:android",
        "@platforms//cpu:aarch64",
    ],
    values = {
        "define": "blst_enabled=true",
    },
)

# gazelle:resolve go github.com/supranational/blst/bindings/go @com_github_supranational_blst//:go_default_library

go_library(
    name = "go_default_library",
    srcs =
        selects.with_or({
            (
                ":blst_enabled_linux_amd64",
                ":blst_enabled_linux_arm64",
                ":blst_enabled_darwin_amd64",
                ":blst_enabled_windows_amd64",
                ":blst_enabled_android_amd64",
                ":blst_enabled_android_arm64",
            ): [
                "aliases.go",
                "doc.go",
                "init.go",
                "public_key.go",
                "secret_key.go",
                "signature.go",
            ],
            "//conditions:default": [
                "stub.go",
            ],
        }),
    importpath = "github.com/prysmaticlabs/prysm/shared/bls/blst",
    visibility = [
        "//shared/bls:__pkg__",
    ],
    deps = selects.with_or({
        (
            ":blst_enabled_linux_amd64",
            ":blst_enabled_linux_arm64",
            ":blst_enabled_darwin_amd64",
            ":blst_enabled_windows_amd64",
            ":blst_enabled_android_amd64",
            ":blst_enabled_android_arm64",
        ): [
            "//shared/bls/common:go_default_library",
            "//shared/featureconfig:go_default_library",
            "//shared/params:go_default_library",
            "//shared/rand:go_default_library",
            "@com_github_dgraph_io_ristretto//:go_default_library",
            "@com_github_pkg_errors//:go_default_library",
            "@com_github_supranational_blst//:go_default_library",
        ],
        "//conditions:default": ["//shared/bls/common:go_default_library"],
    }),
)

# gazelle:ignore
go_test(
    name = "go_default_test",
    srcs = selects.with_or({
        (
            ":blst_enabled_linux_amd64",
            ":blst_enabled_linux_arm64",
            ":blst_enabled_darwin_amd64",
            ":blst_enabled_windows_amd64",
            ":blst_enabled_android_amd64",
            ":blst_enabled_android_arm64",
        ): [
            "public_key_test.go",
            "secret_key_test.go",
        ],
        "//conditions:default": [],
    }),
    deps = selects.with_or({
        (
            ":blst_enabled_linux_amd64",
            ":blst_enabled_linux_arm64",
            ":blst_enabled_darwin_amd64",
            ":blst_enabled_windows_amd64",
            ":blst_enabled_android_amd64",
            ":blst_enabled_android_arm64",
        ): [
            "//shared/bls/blst:go_default_library",
            "//shared/bls/common:go_default_library",
            "//shared/bytesutil:go_default_library",
            "//shared/testutil/assert:go_default_library",
            "//shared/testutil/require:go_default_library",
        ],
        "//conditions:default": [],
    }),
)

# gazelle:ignore
go_test(
    name = "go_signature_test",
    srcs = selects.with_or({
        (
            ":blst_enabled_linux_amd64",
            ":blst_enabled_linux_arm64",
            ":blst_enabled_darwin_amd64",
            ":blst_enabled_windows_amd64",
            ":blst_enabled_android_amd64",
            ":blst_enabled_android_arm64",
        ): [
            "signature_test.go",
        ],
        "//conditions:default": [],
    }),
    embed = [":go_default_library"],
    deps = selects.with_or({
        (
            ":blst_enabled_linux_amd64",
            ":blst_enabled_linux_arm64",
            ":blst_enabled_darwin_amd64",
            ":blst_enabled_windows_amd64",
            ":blst_enabled_android_amd64",
            ":blst_enabled_android_arm64",
        ): [
            "//shared/bls/common:go_default_library",
            "//shared/bytesutil:go_default_library",
            "//shared/testutil/assert:go_default_library",
            "//shared/testutil/require:go_default_library",
        ],
        "//conditions:default": [],
    }),
)

# gazelle:exclude bls_benchmark_test.go
go_test(
    name = "go_benchmark_test",
    size = "small",
    srcs = ["bls_benchmark_test.go"],
    args = [
        "-test.bench=.",
        "-test.benchmem",
        "-test.v",
    ],
    local = True,
    tags = [
        "benchmark",
        "manual",
        "no-cache",
    ],
    deps = [
        ":go_default_library",
        "//shared/bls/common:go_default_library",
        "//shared/bytesutil:go_default_library",
        "//shared/hashutil:go_default_library",
    ],
)
